<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/loose.dtd">
<HTML
><HEAD
><TITLE
>Why use g_print, g_malloc, g_strdup and fellow glib
functions?</TITLE
><META
NAME="GENERATOR"
CONTENT="Modular DocBook HTML Stylesheet Version 1.79"><LINK
REL="HOME"
TITLE="GTK+ FAQ"
HREF="book1.html"><LINK
REL="UP"
TITLE="About GLib"
HREF="c875.html"><LINK
REL="PREVIOUS"
TITLE="Memory does not seem to be released when I free the
list nodes I've allocated"
HREF="x901.html"><LINK
REL="NEXT"
TITLE="What's a GScanner and how do I use one?"
HREF="x918.html"></HEAD
><BODY
CLASS="SECT1"
BGCOLOR="#FFFFFF"
TEXT="#000000"
LINK="#0000FF"
VLINK="#840084"
ALINK="#0000FF"
><DIV
CLASS="NAVHEADER"
><TABLE
SUMMARY="Header navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TH
COLSPAN="3"
ALIGN="center"
>GTK+ FAQ</TH
></TR
><TR
><TD
WIDTH="10%"
ALIGN="left"
VALIGN="bottom"
><A
HREF="x901.html"
ACCESSKEY="P"
>&#60;&#60;&#60; Previous</A
></TD
><TD
WIDTH="80%"
ALIGN="center"
VALIGN="bottom"
>About GLib</TD
><TD
WIDTH="10%"
ALIGN="right"
VALIGN="bottom"
><A
HREF="x918.html"
ACCESSKEY="N"
>Next &#62;&#62;&#62;</A
></TD
></TR
></TABLE
><HR
ALIGN="LEFT"
WIDTH="100%"></DIV
><DIV
CLASS="SECT1"
><H1
CLASS="SECT1"
><A
NAME="AEN908"
>Why use g_print, g_malloc, g_strdup and fellow glib
functions?</A
></H1
><P
>Thanks to Tim Janik who wrote to gtk-list: (slightly
modified)</P
><P
><SPAN
CLASS="QUOTE"
>"Regarding g_malloc(), g_free() and siblings, these
functions are much safer than their libc equivalents. For
example, g_free() just returns if called with NULL. Also, if
USE_DMALLOC is defined, the definition for these functions
changes (in glib.h) to use MALLOC(), FREE() etc... If
MEM_PROFILE or MEM_CHECK are defined, there are even small
statistics made counting the used block sizes (shown by
g_mem_profile() / g_mem_check())."</SPAN
></P
><P
><SPAN
CLASS="QUOTE"
>"Considering the fact that glib provides an interface for
memory chunks to save space if you have lots of blocks that
are always the same size and to mark them ALLOC_ONLY if
needed, it is just straight forward to create a small saver
(debug able) wrapper around the normal malloc/free stuff as
well - just like gdk covers Xlib. ;)"</SPAN
></P
><P
><SPAN
CLASS="QUOTE"
>"Using g_error() and g_warning() inside of applications
like the GIMP that fully rely on gtk even gives the
opportunity to pop up a window showing the messages inside of
a gtk window with your own handler (by using
g_set_error_handler()) along the lines of
<TT
CLASS="LITERAL"
>gtk_print()</TT
> (inside of
gtkmain.c)."</SPAN
></P
></DIV
><DIV
CLASS="NAVFOOTER"
><HR
ALIGN="LEFT"
WIDTH="100%"><TABLE
SUMMARY="Footer navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
><A
HREF="x901.html"
ACCESSKEY="P"
>&#60;&#60;&#60; Previous</A
></TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="book1.html"
ACCESSKEY="H"
>Home</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
><A
HREF="x918.html"
ACCESSKEY="N"
>Next &#62;&#62;&#62;</A
></TD
></TR
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
>Memory does not seem to be released when I free the
list nodes I've allocated</TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="c875.html"
ACCESSKEY="U"
>Up</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
>What's a GScanner and how do I use one?</TD
></TR
></TABLE
></DIV
></BODY
></HTML
>